package com.renu.jdependencyanalyser.utils;

import com.renu.jdependencyanalyser.utils.MyFileUtil;

import javax.swing.*;

public class ImageDialogUtil {
    public static void main(String[] args) {
        //byte[] bytes = MyFileUtil.readFileToBytes("/Users/renu/Documents/high/paper/JDependencyAnalyser/src/main/resources/image/org.example.test.test.MyClass.png");
        String fileName = "/Users/renu/Documents/high/paper/JDependencyAnalyser/src/main/resources/image/org.example.test.test.MyClass.png";
        showImage(fileName,"text");

    }
    public static void showImage(String fileName,String title) {

        ImageIcon icon = new ImageIcon(fileName);
        JLabel label = new JLabel(icon);

        String [] options = {"确定","导出图片"};
        JOptionPane jOptionPane = new JOptionPane(
                label,
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.PLAIN_MESSAGE,
                null,
                options, // 自定义按钮标签
                options[0]);
        JDialog dialog = jOptionPane.createDialog(title);
        dialog.setResizable(true);
        dialog.setVisible(true);
        try{
            Object choice = jOptionPane.getValue();

            // 根据用户选择执行相应操作
            if (choice.equals(options[0])){
                System.out.println("确定");
                //MyFileUtil.deleteFile(fileName);
            }else if (choice.equals(options[1])){
                System.out.println("导出");
            }else{
                System.out.println("关闭");
            }

        }catch (Exception e){
            dialog.dispose(); // 关闭对话框
        }

    }
}
